using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class VitualCameraCenter : NetworkBehaviour
{
    // 需要同步摄像机的位置信息
    private NetworkVariable<Vector3> followTargetPosition = new NetworkVariable<Vector3>();

    void Update()
    {
        if(IsServer) {
            Vector3 targetPosition = CalculationFollowTargetPosition();
            followTargetPosition.Value = targetPosition;
        }
    }

    private Vector3 CalculationFollowTargetPosition() {
        Vector3 pos = Vector3.zero;
        if(!IsServer) return pos;

        pos = PlayersManager.instance.GetPlayersCenterPosition();
        return pos;
    }

    private void LateUpdate() {
        if(IsServer) {
            transform.position = PlayersManager.instance.GetPlayersCenterPosition();
        } else {
            // transform.position = 
            transform.position = Vector3.Lerp(transform.position,followTargetPosition.Value,Time.deltaTime);
        }
    }
}
